package au.com.bellygoodengine.servlets;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import au.com.bellygoodengine.models.Menu;

import com.google.appengine.repackaged.org.json.JSONObject;

@SuppressWarnings("serial")
public class BellyGoodEngineServlet extends AbstractServlet {
	
	private static final Logger log = Logger.getLogger(BellyGoodEngineServlet.class.getName());
	
	@Override
	public void process(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		
		String key = req.getParameter("key");
		String format = req.getParameter("format");
		Object callback = req.getParameter("callback");
        log.info("key: " + key);
        log.info("format: " + format);
        log.info("Callback: " + callback);
		
		Menu menu = new Menu();
		JSONObject jsonObject = new JSONObject(menu);
		jsonObject.remove("class");
		log.info("\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" 
				+ jsonObject.toString()
				+ "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
		);
		
		resp.setContentType("application/json");
//		resp.setContentType("text");
//		callback(jsonObject.toString());
		resp.getWriter().write(jsonObject.toString());
	}
}
